package org.syndicate.domain;

import java.util.List;

import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;
import org.syndicate.util.CalendarUtil;

/**
 * This class expresses drawing out from the facility and receiving the financing. 
 * 
 * @author akiraabe
 */
@RooJavaBean
@RooToString
@RooEntity(inheritanceType = "JOINED")
public class Drawdown extends AbstractTransaction {
	
	private Integer paymentTime;
	private Double rate;	
	
	/**
	 * {@inheritDoc}
	 * <br/>
	 * Drawing out from the facility and receiving the financing. 
	 */
	@Transactional
	@Override
	public AbstractPosition execute() {
		System.out.println("Drawdown#execute");
		
		//TODO Need re-factoring.
		SharePie input = this.getSharePie();
		
		this.setDiscriminator("Drawdown");
		
		// Create new Loan
		Loan loan = new Loan();
		loan.apply(this);
		
		// Find existing Facility
		Facility facility = Facility.findBySharePie(input);
		if (facility == null)
			System.out.println("##### NULL.....#####");
		facility.apply(this);
		
		return loan;
		
	}
}
